package com.fgchen.study.user.client;

import com.fgchen.study.user.domain.User;
import com.fgchen.study.user.service.LoginService;
import com.fgchen.study.user.service.UserService;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.protocol.TMultiplexedProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

/**
 * Created by fgchen on 2017/7/17.
 */
public class MyClient {

    public static void main(String[] args) throws Exception {
        TTransport transport = new TFramedTransport(new TSocket("localhost", 8888));
        TProtocol protocol = new TJSONProtocol(transport);
        TMultiplexedProtocol loginProtocol = new TMultiplexedProtocol(protocol, "LoginService");
        TMultiplexedProtocol userProtocol = new TMultiplexedProtocol(protocol, "UserService");

        LoginService.Client loginClient = new LoginService.Client(loginProtocol);
        UserService.Client userClient = new UserService.Client(userProtocol);

        transport.open();

        userClient.update(new User("hayden", "123456"));

        System.out.println("1.-----------");
        System.out.println(userClient.query("hayden"));
        System.out.println("2.-----------");
        System.out.println(loginClient.login(new User("hayden", "123456")));
        System.out.println("3.-----------");

        transport.close();
    }

}
